{include file='common/head'}

<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;">
    <blockquote class="layui-elem-quote layui-text">
        <div class="demoTable layui-form">
            <div class="layui-input-inline">
                <input type="text" placeholder="请输入管理员名称" name="admin_name" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <select name="depart_id"  lay-search>
                    <option value="">筛选所属部门</option>
                    {foreach $info as $v}
                    <option value="{$v.id}">{$v.depart_name}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="role_id"  lay-search>
                    <option value="">筛选所属角色</option>
                    {foreach $role as $val}
                    <option value="{$val.id}">{$val.name}</option>
                    {/foreach}
                </select>
            </div>
            <button class="layui-btn " data-type="reload"><i class="layui-icon">&#xe615;</i>搜索</button>
            <button class="layui-btn addInfo" style="margin:0;"><i class="layui-icon">&#xe654;</i> 添加</button>
        </div>
    </blockquote>


    <div class="demoTable layui-for">
        <table class="layui-table" lay-data="{height: 'full-100', url:'{:url('admin/admin/get')}', page:true,id:'tableId',loading:true}" lay-filter="tableFilter">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:100,fixed: true,templet:'#id'}">编号</th>
                <th lay-data="{field:'admin_name',templet:'#remb',width:170}">员工名称</th>
                <th lay-data="{field:'phone',templet:'#phone',width:170}">电话</th>
                <th lay-data="{field:'name',width:170,templet:'#role'}">角色</th>
                <th lay-data="{field:'depart_name',templet:'#depart',width:170}">部门</th>
                <th lay-data="{field:'status',width:70, templet: '#status'}">状态</th>
                <th lay-data="{fixed: '', width:180,fixed: 'right',  toolbar: '#barDemo'}">操作</th>
            </tr>
            </thead>
        </table>
        <!--操作功能-->
        <script type="text/html" id="barDemo">
            <a title="编辑" lay-event="edit" href="#"><i class="layui-icon" style="font-size: 25px; color:#029587;line-height: 30px">&#xe642;</i></a>
            <a title="删除" lay-event="delete" href="#"><i class="layui-icon" style="font-size: 25px; color:#029587;line-height: 30px">&#xe640;</i></a>
        </script>

        <!--列-自定义-->
        <script type="text/html" id="status">
            {{#  if(d.status == 1){ }}
            <span style="color: #5FB878" >正常</span>
            {{#  } }}
            {{#  if(d.status == 2){ }}
            <span style="color: #FF5722" >禁用</span>
            {{#  } }}
        </script>

    </div>
    <script src="/static/admin/jquery.js"></script>
    <script type="text/javascript" src="/static/index/layer/layer.js"></script>
    <script type="text/html" id="id">
        <span>{{d.id}}</span>
    </script>
    <script type="text/html" id="remb">
        <span>{{d.admin_name}}</span>
    </script>
    <script type="text/html" id="phone">
        <span>{{d.phone}}</span>
    </script>
    <script type="text/html" id="role">
        <span>{{d.name}}</span>
    </script>
    <script type="text/html" id="depart">
        <span>{{d.depart_name}}</span>
    </script>
</div>
    {include file='common/footer'}
    <!--颜色编辑-->
    <script>
        layui.use(['table','form'], function(){
            var table = layui.table
                ,form = layui.form;
            //搜索提交
            var $ = layui.$, active = {
                reload: function(){
                    var admin_name = $('input[name="admin_name"]').val();
                    var depart_id = $('select[name="depart_id"] option:checked').val();
                    var role_id = $('select[name="role_id"] option:checked').val();
                    //执行重载
                    table.reload('tableId', {
                        where: {
                            admin_name:admin_name,
                            depart_id:depart_id,
                            role_id:role_id,
                        }
                    });
                }
            };
            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            //监听表格复选框选择
            table.on('checkbox(tableFilter)', function(obj){
                console.log(obj)
            });

            //表格功能
            table.on('tool(tableFilter)', function(obj){
                var data = obj.data;
                var event=obj.event;
                switch(event){
                    case 'edit':
                        layer.open({
                            type: 2,
                            title: '编辑更新数据信息',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['100%', '100%'],
                            content: '{:url("admin/Admin/adminInfo")}?id='+data.id,
                            end: function () {
                                table.reload('tableId');
                            },
                        });
                        break;
                    case 'delete':
                        layer.confirm('确定删除么?', function(index){
                            $.ajax({
                                url:'{:url("admin/Admin/deleteAdmin")}',
                                type:'post',
                                dataType:'json',
                                data: {'id':data.id},
                                success:function(val){
                                    if(val.code == 200){
                                        obj.del();
                                        layer.msg(val.msg);
                                    }
                                    if(val.code == 400){
                                        layer.msg(val.msg);
                                    }
                                }
                            });

                        });
                        break;
                }
            });

//      添加信息 url跳转路径
            var url='{:url("Admin/adminInfo")}';
            $('.addInfo').on('click', function() {
                layer.open({
                    type: 2,
                    title: '添加内容信息',
                    shadeClose: true,
                    shade: false,
                    maxmin: true,
                    area: ['100%', '100%'],
                    content: url,
                    end: function () {
                        table.reload('tableId');
                    },
                });
            });
        });
    </script>
    </body>
    </html>